SPB Git forge

spb/polyllm

Public
15commits 1branches 0releases
2.2 MBsize
maindefault branch
13 days agolast push
TypeScript 97.4% SQL 1% JavaScript 0.9% CSS 0.6%
1.1 KB · 30 lines typescript
Raw Blame History
1import { withUser, parseBody, json, ApiError } from "@/lib/api";2import { getEndpoint, updateEndpoint, deleteEndpoint, ENDPOINT_PATCH_SCHEMA } from "@/lib/endpoints/service";3import { LIMITS } from "@/lib/rate-limit";45export const dynamic = "force-dynamic";67type P = { id: string };89/** GET /api/endpoints/[id] → `{ endpoint: PublicEndpoint }` */10export const GET = withUser<P>(async ({ user }, { id }) => {11  const endpoint = await getEndpoint(user.id, id);12  if (!endpoint) throw new ApiError(404, "Endpoint not found", "NOT_FOUND");13  return json({ endpoint });14});1516/** PATCH /api/endpoints/[id] — partial `EndpointInput` (apiKey `null` clears it) → `{ endpoint }` */17export const PATCH = withUser<P>(18  async ({ req, user, ip }, { id }) => {19    const body = await parseBody(req, ENDPOINT_PATCH_SCHEMA, 64_000);20    return json({ endpoint: await updateEndpoint(user.id, id, body, ip) });21  },22  { limit: { ...LIMITS.keySave, key: "endpoint-save" } },23);2425/** DELETE /api/endpoints/[id] → `{ ok: true }` */26export const DELETE = withUser<P>(async ({ user, ip }, { id }) => {27  await deleteEndpoint(user.id, id, ip);28  return json({ ok: true });29});30